import request from "../utils/request";
import {get,STATION} from "./common";

import axios from 'axios';
import {HIS_PORT} from "../utils/sysconstant";

//设置接口服务器地址
let refresh_ip =null;

const api_server = localStorage.getItem('api_server');
if (api_server !== null) {
    refresh_ip = JSON.parse(api_server).ip;
}

let refresh_host="http://"+refresh_ip+":"+HIS_PORT

const service_tmp = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    baseURL: refresh_host,
    //设置请求超时时间
    timeout: 180000
});

service_tmp.interceptors.request.use(
    config => {
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service_tmp.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            return Promise.reject();
        }
    },
    error => {
        console.log(refresh_host)
        console.log(error);
        return Promise.reject();
    }
);


const get_tmp = (api, params, headers) => {
    return service_tmp({
        url: api,
        method: 'get',
        params: params,
        headers: headers
    });
};

function refreshFromHis(){
    return get_tmp('/update/updatePatient', {sno:localStorage.getItem('sno'),stationId:STATION.id});
}

export{
    refreshFromHis,
}